package org.hiucung.hlsdownloader.utils

import android.util.Log
import java.io.File

/**
 * @title: FileUtils
 * @projectName HLS Downloader
 * @description: File工具类
 * @author Kicc
 * @date 2025/8/23 16:13
 */
object FileUtils {

    /**
     * 删除文件列表中的所有文件
     */
    fun deleteFiles(filePaths: List<String>) {
        val results = mutableListOf<Pair<String, Boolean>>()

        for (filePath in filePaths) {
            try {
                val file = File(filePath)
                val deleted = if (file.exists()) {
                    file.delete()
                } else {
                    true // 文件不存在视为删除成功
                }
                results.add(filePath to deleted)

                if (!deleted) {
                    Log.w("FileUtils", "Failed to delete: $filePath")
                }
            } catch (e: Exception) {
                Log.e("FileUtils", "Error deleting $filePath", e)
                results.add(filePath to false)
            }
        }

    }
}